       subroutine run_uhf_ri(icore, isympopa, isympopb, &
                              isymvrta, isymvrtb,         &
                              isymmo, nvmax, nomax, nmo)
!    
      use mod_ri 
      use mod_symm
      use mod_iop
      use mod_orbit
      use mod_size
      use mod_ioff
      implicit none
      integer*8, intent(in) :: nmo, nvmax, nomax, isymmo(nmo, 8, 2)
      integer*8, intent(in) :: isymvrta(nvmax,8), isymvrtb(nvmax,8)
      integer*8, intent(in) :: isympopa(nomax,8), isympopb(nomax,8)
      real*8, intent(in) :: icore(*)
      double precision dtmp
!
      integer*8 maxcor, iintfp, iflags
!
      double precision eccsd, escf, scalfact, tmp
      double precision, allocatable::ea(:), eb(:)
!
      integer*8 :: ncycle, a, b
!
      integer*8:: nbasis, nsol, nbas2, no2, nv2, nvo, no4, nv2o2
      integer*8:: iread, isox, isoy, isoz, itmp1, itmp2, imoc, norbs
      integer*8:: iaopop(8), irrep, i, j, nsize, idx, ioffa
      integer*8:: irrepab, irrepcd, irrepc, irrepd
!            
      integer*8:: iijkl, iiabj, iabij, iijka, i4, i5, i6
      integer*8:: nv3, nv3o, i0, i1, i2, i3, iend, nvt
      integer*8:: icontl, nabcdab, numab, numcd, naux8t(8)
      integer*8:: maxcor1, istat, irrepmo(nmo,2), ioffmo(nmo,2)
      integer*8:: c, d, numc, numd, irrepci, numi, irrepi
      integer*8:: numab1, numab2, numab3, numcd1, numcd2, numcd3
      integer*8:: vstart, nfirst, nread, nleft, idx2, nsize2
      double precision tt1, tt2,rt1, rt2, rt3, rt4, rt5, rt6 

      integer, allocatable :: isymnaux(:,:)
      real*8, allocatable :: fijaar(:,:), fijaai(:,:)
      real*8, allocatable :: fijabr(:,:), fijabi(:,:)
      real*8, allocatable :: fiaaar(:,:), fiaaai(:,:)
      real*8, allocatable :: fiaabr(:,:), fiaabi(:,:)
      real*8, allocatable :: fabaar(:,:), fabaai(:,:)
      real*8, allocatable :: fababr(:,:), fababi(:,:)
      real*8, allocatable :: fijr(:,:), fiji(:,:)
      real*8, allocatable :: fiar(:,:), fiai(:,:)
      real*8, allocatable :: fabr(:,:), fabi(:,:)
      real*8, allocatable :: iaam(:,:,:), ibbm(:,:,:)
      real*8, allocatable :: rivv(:), rivo(:), rioo(:)
      real*8, allocatable :: rivv2(:), rivo2(:), rioo2(:)
      real*8, allocatable :: rivvtmp(:), rioo_b(:), rivo_b(:), rivv_b(:)
      real*8, allocatable :: ea_resort(:), eb_resort(:)
!
      character*12 string2, sfname
      logical :: lsoineom, lscalar, lbdf, lscalsoc
!     
      integer*8 memsize, rec_char, n, k, nvv, nvo, noo
      integer*8 nvv_b, nvo_b, noo_b
      integer*8 fcstar, nbas, nocca, noccb, nirreptmp
      integer*8, external :: idsymsz, irpdso, isymoffso, idsymsoc
      double precision, external :: dnrm2, nrm2so
!     write(6,*)'begin clmoioso'

      call walltimeso(tt1)
      zorb(1) = 1
      zorb(2:8) = 0

      naux8t(1:8) = 0
      open(44, file='dfpar.data', form='formatted')
      read(44, *) naux, n, n
      do i = 1, nirrep
         read(44, *) naux8t(i)
         naux8(i) = naux8t(i)
      enddo
      close(44)

      idx = 0  
      do n = 1, nmo 
         do irrep = 1, nirrep
            do i = 1, pop(irrep,1)+vrt(irrep,1)
               if(isymmo(i, irrep,1)==n) then 
                  idx = idx + 1
                  irrepmo(n,1) = irrep
                  ioffmo(n,1) = i 
               endif
            enddo
            do i = 1, pop(irrep,2)+vrt(irrep,2)
               if(isymmo(i, irrep,2)==n) then 
                  idx = idx + 1
                  irrepmo(n,2) = irrep
                  ioffmo(n,2) = i 
               endif
            enddo
         enddo
      enddo
      naux8t(1:8) = 0
      open(44, file='dfpar.data', form='formatted')
      read(44, *) naux, n, n
      if (n/=nmo) then
          write(6,*) 'error!', n, nmo
          stop
      endif
      allocate(isymnaux(naux, 8), STAT = istat)
      do i = 1, nirrep
         read(44, *) naux8t(i)
         naux8(i) = naux8t(i)
      enddo
      close(44)

      do j = 1, 8
      do i = 1, naux
         isymnaux(i,j) = i
      enddo
      enddo

!      naux8 = naux 
      nvv = idsymsoc(1, naux8t, zorb, 1, vrta, vrta, 1) 
      nvo = idsymsoc(1, naux8t, zorb, 1, vrta, popa, 1)
      noo = idsymsoc(1, naux8t, zorb, 1, popa, popa, 1)
      nvv_b = idsymsoc(1, naux8t, zorb, 1, vrtb, vrtb, 1) 
      nvo_b = idsymsoc(1, naux8t, zorb, 1, vrtb, popb, 1)
      noo_b = idsymsoc(1, naux8t, zorb, 1, popb, popb, 1)
      write(6,*)' test here in run_rhf_ri_s'

      write(6, '(1x, a, f6.2)') 'size of rivv(Gb):',             &
                               dble(nvv*8.d0/(1024*1024*1024))    
     write(6, '(1x, a, f6.2)') 'size of rivo(Gb):',              &
                               dble(nvo*8.d0/(1024*1024*1024))    
     write(6, '(1x, a, f6.2)') 'size of rioo(Gb):',              &
                               dble(noo*8.d0/(1024*1024*1024))    
     call clmoioso0(1, icore, naux8t, zorb, 1,                 &
                      vrta, vrta, 1, 'RIVVAA__')                
     call clmoioso0(1, icore, naux8t, zorb, 1,                 &
                      vrta, popa, 1, 'RIVOAA__')                
     call clmoioso0(1, icore, naux8t, zorb, 1,                 &
                      popa, popa, 1, 'RIOOAA__')                
     call clmoioso0(1, icore, naux8t, zorb, 1,                 &
                      vrtb, vrtb, 1, 'RIVVBB__')                
     call clmoioso0(1, icore, naux8t, zorb, 1,                 &
                      vrtb, popb, 1, 'RIVOBB__')                
     call clmoioso0(1, icore, naux8t, zorb, 1,                 &
                      popb, popb, 1, 'RIOOBB__')

     i0 = 1
     i1 = i0 + nvv*2
     i2 = i1 + nvo*2
     i3 = i2 + noo*2
     i4 = i3 + nvv_b*2
     i5 = i4 + nvo_b*2
     i6 = i5 + noo_b*2
!     write(6,*)'i', i0, i1, i2, i3, i4, i5, i6
     call uri_resort_symm(icore(i0), icore(i1), icore(i2), icore(i3), &
                     icore(i4), icore(i5), icore(i6),  nmo, isymnaux, &
                     isymvrta, isympopa, nvmax, nomax, naux8t)
     write(6,*)'finished ri_resort'
     allocate(rivv(nvv_b), rivo(max(nvo, nvo_b)), rioo(noo), STAT = istat)
     call checkalloc(istat, 'rivv ... in run_rhf_ri')
     allocate(rivo_b(nvo_b), rioo_b(noo_b), rivv_b(nvv_b), STAT = istat)

!    call ri_resort_symm(iaam, icore(i0), icore(i1), icore(i2), nmo, isymnaux, 
!                        isymvrta, isympopa, nvmax, nomax, naux8t)
     call myicopyso(icore(i0), rivv, nvv)
     call myicopyso(icore(i1), rivo, nvo)
     call myicopyso(icore(i2), rioo, noo)
     call putallso(rivv, 1, 'RIVVAA__') 
     call putallso(rivo, 1, 'RIVOAA__') 
     call putallso(rioo, 1, 'RIOOAA__')
     if(ldebug) then 
         nsize = idsymsoc(1, naux8t, zorb, 1, vrta, vrta, 1) 
         write(6,*)'norm of rivv_a', nsize, nrm2so(nsize, rivv, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, vrta, popa, 1) 
         write(6,*)'norm of rivo_a', nsize, nrm2so(nsize, rivo, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, popa, popa, 1) 
         write(6,*)'norm of rioo_a', nsize, nrm2so(nsize, rioo, 1)
     endif

     call myicopyso(icore(i3), rivv, nvv_b)
     call myicopyso(icore(i4), rivo, nvo_b)
     call myicopyso(icore(i5), rioo, noo_b)
     call putallso(rivv, 1, 'RIVVBB__') 
     call putallso(rivo, 1, 'RIVOBB__') 
     call putallso(rioo, 1, 'RIOOBB__')
     if(ldebug) then 
         nsize = idsymsoc(1, naux8t, zorb, 1, vrtb, vrtb, 1) 
         write(6,*)'norm of rivv_b', nsize, nrm2so(nsize, rivv, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, vrtb, popb, 1) 
         write(6,*)'norm of rivo_b', nsize, nrm2so(nsize, rivo, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, popb, popb, 1) 
         write(6,*)'norm of rioo_b', nsize, nrm2so(nsize, rioo, 1)
     endif
     open(44, file='naux8', form='formatted')
     write(44,*) naux8t 
     close(44)
     call walltimeso(tt2)
     write(6,*)'cpu_time for initio------', tt2-tt1
!=======================================================================
!------------------AA---------------------------------------------------
!=======================================================================
     call getallso(rioo, 1, 'RIOOAA__')
     call getallso(rivo, 1, 'RIVOAA__')
     call getallso(rivv, 1, 'RIVVAA__')
     if(ldebug) then 
         nsize = idsymsoc(1, naux8t, zorb, 1, vrta, vrta, 1) 
         write(6,*)'norm of rivv_a', nsize, nrm2so(nsize, rivv, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, vrta, popa, 1) 
         write(6,*)'norm of rivo_a', nsize, nrm2so(nsize, rivo, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, popa, popa, 1) 
         write(6,*)'norm of rioo_a', nsize, nrm2so(nsize, rioo, 1)
     endif
     call clmoioso0(1, icore, pop(1,1), pop(1,1), 0,&
                          pop(1,1), pop(1,1), 0, 'IJKLAA__')
     call clmoioso0(1, icore, pop(1,1), pop(1,1), 0,&
                          pop(1,1), vrt(1,1), 1, 'IJKAAA__')
     call clmoioso0(1, icore, vrt(1,1), vrt(1,1), 0,&
                        pop(1,1), pop(1,1), 0, 'ABIJAA__')
     call clmoioso0(1, icore, vrt(1,1), pop(1,1), 1,&
                           vrt(1,1), pop(1,1), 1, 'BIAJAAAA')
    if(eri_level==0.or.eri_level==1) then
     call clmoioso0(1, icore, vrt(1,1), vrt(1,1), 0,&
                         vrt(1,1), pop(1,1), 1, 'ABCIAA__')
    endif
    if(eri_level==0) then
     call clmoioso0(1, icore, vrt(1,1), vrt(1,1), 0,&
                         vrt(1,1), vrt(1,1), 0, 'ABCDAA__')
    endif
     call VmnpqVmnrs_to_Vpqrs(rioo, rioo, 1, 1, naux8t, zorb, 1,  &
                     popa, popa, 1, popa, popa, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popa, popa, 1, popa, popa, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popa, popa,popa,popa,& 
                  icore, 1, '1324') 
     call iassymso(icore(nsize+1), icore, 1, popa, popa, popa, popa, 1)
     call icompso(icore, icore(nsize+1), popa, popa, 1, 0, &
                  popa, popa, 0, 1, 1)
     call putallso(icore(nsize+1), 1, 'IJKLAA__')

     call VmnpqVmnrs_to_Vpqrs(rioo, rivo, 1, 1, naux8t, zorb, 1,  &
                     popa, popa, 1, vrta, popa, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popa, popa, 1, vrta, popa, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popa, popa,vrta,popa,& 
                  icore, 1, '1423') 
     call iassymso(icore(nsize+1), icore, 1, popa, popa, popa, vrta, 5)
     call putallso(icore, 1, 'IJKAAA__')

     call VmnpqVmnrs_to_Vpqrs(rivo, rivo, 1, 1, naux8t, zorb, 1,  &
                     vrta, popa, 1, vrta, popa, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, vrta, popa, 1, vrta, popa, 1)
     call sstgenso(icore, icore(nsize+1), nsize, vrta, popa,vrta,popa,& 
                  icore, 1, '1324') 
     call iassymso(icore(nsize+1), icore, 1, vrta, vrta, popa, popa, 5)
     call icompso(icore, icore(nsize+1), vrta, vrta, 0, 1, &
                                         popa, popa, 1, 0, 1)
     call putallso(icore(nsize+1), 1, 'ABIJAA__')
!<IA||BJ>=<IA|BJ>-<IA|JB> = (IB|AJ)-(IJ|AB)
     nsize = idsymsoc(1, vrta, popa, 1, vrta, popa, 1)
     ! get(IJ|AB)
     call VmnpqVmnrs_to_Vpqrs(rioo, rivv, 1, 1, naux8t, zorb, 1,  &
                     popa, popa, 1, vrta, vrta, 1, icore, 1, 1.d0,0.d0)
     ! sstgen (IJ|AB) to BIAJ
     call sstgenso(icore, icore(nsize+1), nsize, popa, popa,vrta,vrta,& 
                  icore, 1, '4132')
     !(IB|AJ)=(BI|AJ) 
     call VmnpqVmnrs_to_Vpqrs(rivo, rivo, 1, 1, naux8t, zorb, 1,  &
                     vrta, popa, 1, vrta, popa, 1, icore, 1, 1.d0,0.d0)
     call axpyso(nsize, -1.d0, icore(nsize+1), 1, icore, 1)
     call putallso(icore, 1, 'BIAJAAAA')

     if(eri_level==1.or.eri_level==0) then
     do irrepi = 1, nirrep
        numi = popa(irrepi) 
        do i = 1, numi 
           call getpqrvo_ri2(icore, i, irrepi, rivv, rivo, 0, 1)
           call putpqrso(icore, i, irrepi, 1, 'ABCIAA__') 
        enddo
     enddo
     endif

     if(eri_level==0) then
     do irrepd = 1, nirrep
        numd = vrta(irrepd) 
        do d = 1, numd 
           call getpqrvv_ri2(icore, d, irrepd, rivv, rivv, 0, 1)
           call putpqrso(icore, d, irrepd, 1, 'ABCDAA__') 
        enddo
     enddo
     endif 
     if(ldebug) then
        write(6,*)'naux8', naux8t 
        call getallso(icore, 1, 'IJKLAA__')
        nsize2 = idsymsoc(1, popa, popa, 0, popa, popa, 0)
        write(6,*)'norm of IJKLAA  ',  nrm2so(nsize2, icore,1)
        call getallso(icore, 1, 'IJKAAA__')
        nsize2 = idsymsoc(1, popa, popa, 0, popa, vrta, 1)
        write(6,*)'norm of IJKAAA  ',  nrm2so(nsize2, icore,1)
        call getallso(icore, 1, 'ABIJAA__')
        nsize2 = idsymsoc(1, vrta, vrta, 0, popa, popa, 0)
        write(6,*)'norm of ABIJAA  ',  nrm2so(nsize2, icore,1)
        call getallso(icore, 1, 'BIAJAAAA')
        nsize = idsymsoc(1,vrta,popa, 1,vrta,popa, 1)
        write(6,*)'norm of BIAJAAAA', nrm2so(nsize, icore, 1)
     if(eri_level==1.or.eri_level==0) then
        call getallso(icore, 1, 'ABCIAA__')
        nsize = idsymsoc(1,vrta,vrta, 0,vrta,popa, 1)
        write(6,*)'norm of ABCIAA  ', nrm2so(nsize, icore, 1)
     endif
     if(eri_level==0) then
        call getallso(icore, 1, 'ABCDAA__')
        nsize = idsymsoc(1,vrta,vrta, 0,vrta,vrta, 0)
        write(6,*)'norm of ABCDAA  ', nrm2so(nsize, icore, 1)
     endif
     endif
!=======================================================================
!------------------BB---------------------------------------------------
!=======================================================================
    call getallso(rioo_b, 1, 'RIOOBB__')
    call getallso(rivo_b, 1, 'RIVOBB__')
    call getallso(rivv_b, 1, 'RIVVBB__')
     if(ldebug) then
         nsize = idsymsoc(1, naux8t, zorb, 1, vrtb, vrtb, 1)
         write(6,*)'norm of rivv_b', nsize, nrm2so(nsize, rivv_b, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, vrtb, popb, 1)
         write(6,*)'norm of rivo_b', nsize, nrm2so(nsize, rivo_b, 1)
         nsize = idsymsoc(1, naux8t, zorb, 1, popb, popb, 1)
         write(6,*)'norm of rioo_b', nsize, nrm2so(nsize, rioo_b, 1)
     endif
     call clmoioso0(1, icore, pop(1,2), pop(1,2), 0,&
                          pop(1,2), pop(1,2), 0, 'IJKLBB__')
     call clmoioso0(1, icore, pop(1,2), pop(1,2), 0,&
                          pop(1,2), vrt(1,2), 1, 'IJKABB__')
     call clmoioso0(1, icore, vrt(1,2), vrt(1,2), 0,&
                        pop(1,2), pop(1,2), 0, 'ABIJBB__')
     call clmoioso0(1, icore, vrt(1,2), pop(1,2), 1,&
                           vrt(1,2), pop(1,2), 1, 'BIAJBBBB')
    if(eri_level==0.or.eri_level==1) then
     call clmoioso0(1, icore, vrt(1,2), vrt(1,2), 0,&
                         vrt(1,2), pop(1,2), 1, 'ABCIBB__')
    endif
    if(eri_level==0) then
     call clmoioso0(1, icore, vrt(1,2), vrt(1,2), 0,&
                         vrt(1,2), vrt(1,2), 0, 'ABCDBB__')
    endif
     call VmnpqVmnrs_to_Vpqrs(rioo_b, rioo_b, 1, 1, naux8t, zorb, 1,  &
                     popb, popb, 1, popb, popb, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popb, popb, 1, popb, popb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popb, popb,popb,popb,&
                  icore, 1, '1324')
     call iassymso(icore(nsize+1), icore, 1, popb, popb, popb, popb, 1)
     call icompso(icore, icore(nsize+1), popb, popb, 1, 0, &
                  popb, popb, 0, 1, 1)
     call putallso(icore(nsize+1), 1, 'IJKLBB__')

     call VmnpqVmnrs_to_Vpqrs(rioo_b, rivo_b, 1, 1, naux8t, zorb, 1,  &
                     popb, popb, 1, vrtb, popb, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popb, popb, 1, vrtb, popb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popb, popb,vrtb,popb,&
                  icore, 1, '1423')
     call iassymso(icore(nsize+1), icore, 1, popb, popb, popb, vrtb, 5)
     call putallso(icore, 1, 'IJKABB__')

     call VmnpqVmnrs_to_Vpqrs(rivo_b, rivo_b, 1, 1, naux8t, zorb, 1,  &
                     vrtb, popb, 1, vrtb, popb, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, vrtb, popb, 1, vrtb, popb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, vrtb, popb,vrtb,popb,&
                  icore, 1, '1324')
     call iassymso(icore(nsize+1), icore, 1, vrtb, vrtb, popb, popb, 5)
     call icompso(icore, icore(nsize+1), vrtb, vrtb, 0, 1, &
                                         popb, popb, 1, 0, 1)
     call putallso(icore(nsize+1), 1, 'ABIJBB__')
!<IA||BJ>=<IA|BJ>-<IA|JB> = (IB|AJ)-(IJ|AB)
     nsize = idsymsoc(1, vrtb, popb, 1, vrtb, popb, 1)
     ! get(IJ|AB)
     call VmnpqVmnrs_to_Vpqrs(rioo_b, rivv_b, 1, 1, naux8t, zorb, 1,  &
                     popb, popb, 1, vrtb, vrtb, 1, icore, 1, 1.d0,0.d0)
     ! sstgen (IJ|AB) to BIAJ
     call sstgenso(icore, icore(nsize+1), nsize, popb, popb,vrtb,vrtb,&
                  icore, 1, '4132')
     !(IB|AJ)=(BI|AJ) 
     call VmnpqVmnrs_to_Vpqrs(rivo_b, rivo_b, 1, 1, naux8t, zorb, 1,  &
                     vrtb, popb, 1, vrtb, popb, 1, icore, 1, 1.d0,0.d0)
     call axpyso(nsize, -1.d0, icore(nsize+1), 1, icore, 1)
     call putallso(icore, 1, 'BIAJBBBB')

     if(eri_level==1.or.eri_level==0) then
       do irrepi = 1, nirrep
          numi = popb(irrepi)
          do i = 1, numi
             call getpqrvo_ri2(icore, i, irrepi, rivv_b, rivo_b, 0, 2)
             call putpqrso(icore, i, irrepi, 1, 'ABCIBB__')
          enddo
       enddo
     endif

     if(eri_level==0) then
       do irrepd = 1, nirrep
          numd = vrtb(irrepd)
          do d = 1, numd
             call getpqrvv_ri2(icore, d, irrepd, rivv_b, rivv_b, 0, 2)
             call putpqrso(icore, d, irrepd, 1, 'ABCDBB__')
          enddo
       enddo
     endif
     if(ldebug) then
        write(6,*)'naux8', naux8t
        call getallso(icore, 1, 'IJKLBB__')
        nsize2 = idsymsoc(1, popb, popb, 0, popb, popb, 0)
        write(6,*)'norm of IJKLBB  ',  nrm2so(nsize2, icore,1)
        call getallso(icore, 1, 'IJKABB__')
        nsize2 = idsymsoc(1, popb, popb, 0, popb, vrtb, 1)
        write(6,*)'norm of IJKABB  ',  nrm2so(nsize2, icore,1)
        call getallso(icore, 1, 'ABIJBB__')
        nsize2 = idsymsoc(1, vrtb, vrtb, 0, popb, popb, 0)
        write(6,*)'norm of ABIJBB  ',  nrm2so(nsize2, icore,1)
        call getallso(icore, 1, 'BIAJBBBB')
        nsize = idsymsoc(1,vrtb,popb, 1,vrtb,popb, 1)
        write(6,*)'norm of BIAJBBBB', nrm2so(nsize, icore, 1)
     if(eri_level==1.or.eri_level==0) then
        call getallso(icore, 1, 'ABCIBB__')
        nsize = idsymsoc(1,vrtb,vrtb, 0,vrtb,popb, 1)
        write(6,*)'norm of ABCIBB  ', nrm2so(nsize, icore, 1)
     endif
     if(eri_level==0) then
        call getallso(icore, 1, 'ABCDBB__')
        nsize = idsymsoc(1,vrtb,vrtb, 0,vrtb,vrtb, 0)
        write(6,*)'norm of ABCDBB  ', nrm2so(nsize, icore, 1)
     endif
     endif
!     stop
!=======================================================================
!------------------AB---------------------------------------------------
!=======================================================================
     call clmoioso0(1, icore, popa, popb, 1,&
                         popa, popb, 1, 'IJKLAB__')
     call clmoioso0(1, icore, pop(1,1), pop(1,2), 1, &
                           pop(1,1), vrt(1,2), 1, 'IJKAAB__')
     call clmoioso0(1, icore, pop(1,2), pop(1,1), 1, &
                           pop(1,2), vrt(1,1), 1, 'IJKABA__')
     call clmoioso0(1, icore, vrt(1,1), vrt(1,2), 1,&
                         pop(1,1), pop(1,2), 1, 'ABIJAB__')
     call clmoioso0(1, icore, vrt(1,1), pop(1,2), 1,&
                          vrt(1,1), pop(1,2), 1, 'BIAJABAB')
     call clmoioso0(1, icore, vrt(1,1), pop(1,1), 1,&
                          vrt(1,2), pop(1,2), 1, 'BIAJAABB')
     call clmoioso0(1, icore, vrt(1,2), pop(1,1), 1,&
                            vrt(1,2), pop(1,1), 1, 'BIAJBABA')
    if(eri_level==0.or.eri_level==1) then
     call clmoioso0(1, icore, vrt(1,1), vrt(1,2), 1,&
                          vrt(1,1), pop(1,2), 1, 'ABCIAB__')
     call clmoioso0(1, icore, vrt(1,2), vrt(1,1), 1,&
                          vrt(1,2), pop(1,1), 1, 'ABCIBA__')
    endif
    if(eri_level==0) then
     call clmoioso0(1, icore, vrt(1,1), vrt(1,2), 1,&
                          vrt(1,1), vrt(1,2), 1, 'ABCDAB__')
    endif
     call VmnpqVmnrs_to_Vpqrs(rioo, rioo_b, 1, 1, naux8t, zorb, 1,& 
                     popa, popa, 1, popb, popb, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popa, popb, 1, popa, popb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popa, popa,popb,popb,& 
                  icore, 1, '1324') 
     call putallso(icore(nsize+1), 1, 'IJKLAB__')

     call VmnpqVmnrs_to_Vpqrs(rioo, rivo_b, 1, 1, naux8t, zorb, 1,& 
                     popa, popa, 1, vrtb, popb, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popa, popb, 1, popa, vrtb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popa, popa,vrtb,popb,& 
                  icore, 1, '1423') 
     call putallso(icore(nsize+1), 1, 'IJKAAB__')

     call VmnpqVmnrs_to_Vpqrs(rioo_b, rivo, 1, 1, naux8t, zorb, 1,& 
                     popb, popb, 1, vrta, popa, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, popa, popb, 1, popb, vrta, 1)
     call sstgenso(icore, icore(nsize+1), nsize, popb, popb,vrta,popa,& 
                  icore, 1, '1423') 
     call putallso(icore(nsize+1), 1, 'IJKABA__')

     call VmnpqVmnrs_to_Vpqrs(rivo , rivo_b, 1, 1, naux8t, zorb, 1,& 
                     vrta, popa, 1, vrtb, popb, 1, icore, 1, 1.d0,0.d0)
     nsize = idsymsoc(1, vrta, vrtb, 1, popa, popb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, vrta, popa,vrtb,popb,& 
                  icore, 1, '1324') 
     call putallso(icore(nsize+1), 1, 'ABIJAB__')
! <Ia||Bj>=(BI|aj)
     call VmnpqVmnrs_to_Vpqrs(rivo , rivo_b, 1, 1, naux8t, zorb, 1,& 
                     vrta, popa, 1, vrtb, popb, 1, icore, 1, 1.d0,0.d0)
     call putallso(icore, 1, 'BIAJAABB')
! BiAj = <iA||Bj> = -<iA|jB>= -(ij|AB) = - (BA|ij)
     call VmnpqVmnrs_to_Vpqrs(rivv , rioo_b, 1, 1, naux8t, zorb, 1,& 
                     vrta, vrta, 1, popb, popb, 1, icore, 1, -1.d0,0.d0)
     nsize = idsymsoc(1, vrta, vrta, 1, popb, popb, 1)
     call sstgenso(icore, icore(nsize+1), nsize, vrta, vrta,popb,popb,& 
                  icore, 1, '1324') 
     call putallso(icore(nsize+1), 1, 'BIAJABAB')
! bIaJ = <Ia||bJ> = -<Ia|Jb>= -(IJ|ab) = - (ba|IJ)
     call VmnpqVmnrs_to_Vpqrs(rivv_b , rioo, 1, 1, naux8t, zorb, 1,& 
                     vrtb, vrtb, 1, popa, popa, 1, icore, 1, -1.d0,0.d0)
     nsize = idsymsoc(1, vrtb, vrtb, 1, popa, popa, 1)
     call sstgenso(icore, icore(nsize+1), nsize, vrtb, vrtb,popa,popa,& 
                  icore, 1, '1324') 
     call putallso(icore(nsize+1), 1, 'BIAJBABA')
     if(eri_level==1.or.eri_level==0) then
        do irrepi = 1, nirrep
           numi = popb(irrepi)
           do i = 1, numi
              call getpqrvo_ri2(icore, i, irrepi, rivv, rivo_b, 1, 3)
              call putpqrso(icore, i, irrepi, 1, 'ABCIAB__')
           enddo
        enddo
        do irrepi = 1, nirrep
           numi = popa(irrepi)
           do i = 1, numi
              call getpqrvo_ri2(icore, i, irrepi, rivv_b, rivo, 1, 4)
              call putpqrso(icore, i, irrepi, 1, 'ABCIBA__')
           enddo
        enddo
     endif

     if(eri_level==0) then
        do irrepd = 1, nirrep
           numd = vrtb(irrepd)
           do d = 1, numd
              call getpqrvv_ri2(icore, d, irrepd, rivv, rivv_b, 1, 3)
              call putpqrso(icore, d, irrepd, 1, 'ABCDAB__')
           enddo
        enddo
     endif
     !
    if(ldebug) then
      write(6,*)'====================ABAB===================='
      call getallso(icore, 1, 'IJKLAB__')
      nsize = idsymsoc(1,popa,popb, 1,popa,popb, 1)
      write(6,*)'norm of IJKLAB  ', nrm2so(nsize, icore, 1)

      call getallso(icore, 1, 'IJKAAB__')
      nsize = idsymsoc(1,popa,popb, 1,popa,vrtb, 1)
      write(6,*)'norm of IJKAAB  ', nrm2so(nsize, icore, 1)

      call getallso(icore, 1, 'IJKABA__')
      nsize = idsymsoc(1,popb,popa, 1,popb,vrta, 1)
      write(6,*)'norm of IJKABA  ', nrm2so(nsize, icore, 1)

      call getallso(icore, 1, 'ABIJAB__')
      nsize = idsymsoc(1,vrta,vrtb, 1,popa,popb, 1)
      write(6,*)'norm of ABIJAB  ', nrm2so(nsize, icore, 1)

      call getallso(icore, 1, 'BIAJAABB')
      nsize = idsymsoc(1,vrta,popa, 1,vrtb,popb, 1)
      write(6,*)'norm of BIAJAABB', nrm2so(nsize, icore, 1)

      call getallso(icore, 1, 'BIAJABAB')
      nsize = idsymsoc(1,vrta,popb, 1,vrta,popb, 1)
      write(6,*)'norm of BIAJABAB', nrm2so(nsize, icore, 1)

      nsize = idsymsoc(1,vrtb,popa, 1,vrtb,popa, 1)
      call getallso(icore, 1, 'BIAJBABA')
      write(6,*)'norm of BIAJBABA', nrm2so(nsize, icore, 1)

      if(eri_level==0.or.eri_level==1) then
         call getallso(icore, 1, 'ABCIAB__')
         nsize = idsymsoc(1,vrta,vrtb, 1,vrta,popb, 1)
         write(6,*)'norm of ABCIAB  ', nrm2so(nsize, icore, 1)
         
         call getallso(icore, 1, 'ABCIBA__')
         nsize = idsymsoc(1,vrtb,vrta, 1,vrtb,popa, 1)
         write(6,*)'norm of ABCIBA  ', nrm2so(nsize, icore, 1)
      endif
      if(eri_level==0) then
         call getallso(icore, 1, 'ABCDAB__')
         nsize = idsymsoc(1,vrta,vrtb, 1,vrta,vrtb, 1)
         write(6,*)'norm of ABCDAB  ', nrm2so(nsize, icore, 1)
      endif
     endif

     return
      end



